| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | Public Attributes | List of all members
nkMaths::Quaternion Class Reference

A quaternion, symbolizing rotations as a 4D vector. More...

## Public Member Functions
| Quaternion () noexcept
| Quaternion (float x, float y, float z, float w) noexcept
| Quaternion (const Vector &axis, float angle) noexcept
| Quaternion (const Vector &eulerAngles) noexcept
| Quaternion (const Vector &a, const Vector &b) noexcept
| Quaternion (const Matrix &mat) noexcept
| Quaternion (const Quaternion &other) noexcept
Vector | getAsEulerAngles () const
Vector | getAsAxisAngle () const
Quaternion & | setFromAxisAngle (const Vector &axis, float angle)
Quaternion & | setFromEuler (const Vector &angles)
Quaternion & | setFromRotationBetween (const Vector &a, const Vector &b)
Quaternion & | setFromOrientationMatrix (const Matrix &mat)
Quaternion & | setFromTransformationMatrix (const Matrix &mat)
Vector | transform (const Vector &vector) const
Vector & | apply (Vector &vector) const
nkMemory::String | toString () const
Quaternion & | fromString (nkMemory::StringView str)
Quaternion & | operator= (const Quaternion &other) noexcept
Vector | operator* (const Vector &other) const
Quaternion | operator* (const Quaternion &other) const
void | operator*= (const Quaternion &other)
bool | operator== (const Quaternion &other) const

## Public Attributes
float | _x
| X component of the quaternion.
float | _y
| Y component of the quaternion.
float | _z
| Z component of the quaternion.
float | _w
| W component of the quaternion.

## Detailed Description

A quaternion, symbolizing rotations as a 4D vector.

The equation for the quaternion is considered as : xi + yj + zk + w.

## Constructor & Destructor Documentation

## ◆ Quaternion() [1/7]

nkMaths::Quaternion::Quaternion | ( |  | ) |
| noexcept

Default constructor. Defaults to (0, 0, 0, 1), encoding no rotation.

## ◆ Quaternion() [2/7]

nkMaths::Quaternion::Quaternion | ( | float | x,
|  | float | y,
|  | float | z,
|  | float | w
| ) |  |
| noexcept

Filling constructor.

Parameters

  x | The x component.
  y | The y component.
  z | The z component.
  w | The w component.

## ◆ Quaternion() [3/7]

nkMaths::Quaternion::Quaternion | ( | const Vector & | axis,
|  | float | angle
| ) |  |
| noexcept

Axis angle constructor.

Parameters

  axis | The axis of rotation to consider.
  angle | The angle around this axis, in radians.

## ◆ Quaternion() [4/7]

nkMaths::Quaternion::Quaternion | ( | const Vector & | eulerAngles | ) |
| noexcept

Euler angles constructor.

Parameters

  eulerAngles | The euler angles, considering rotation in ZYX (Yaw-Pitch-Roll) order.

## ◆ Quaternion() [5/7]

nkMaths::Quaternion::Quaternion | ( | const Vector & | a,
|  | const Vector & | b
| ) |  |
| noexcept

Direction to direction constructor.

Parameters

  a | The vector to rotate from.
  b | The vector to rotate to.

## ◆ Quaternion() [6/7]

nkMaths::Quaternion::Quaternion | ( | const Matrix & | mat | ) |
| noexcept

Matrix constructor.

Parameters

  mat | The matrix from which to extract the rotation.

## ◆ Quaternion() [7/7]

nkMaths::Quaternion::Quaternion | ( | const Quaternion & | other | ) |
| noexcept

Copy constructor.

Parameters

  other | The quaternion to copy.

## Member Function Documentation

## ◆ getAsEulerAngles()

Vector nkMaths::Quaternion::getAsEulerAngles | ( |  | ) | const

Returns
  The quaternion translated as euler angles, encoded with ZYX ordering (Yaw-Pitch-Roll).

## ◆ getAsAxisAngle()

Vector nkMaths::Quaternion::getAsAxisAngle | ( |  | ) | const

Returns
  The quaternion translated as an axis angle vector (xyz axis, w angle in radians).

## ◆ setFromAxisAngle()

Quaternion& nkMaths::Quaternion::setFromAxisAngle | ( | const Vector & | axis,
|  | float | angle
| ) |  |

Sets the quaternion from an axis and angle pair.

Parameters

  axis | The axis to rotate around.
  angle | The angle to rotate, in radians.

Returns
  Reference over caller.

## ◆ setFromEuler()

Quaternion& nkMaths::Quaternion::setFromEuler | ( | const Vector & | angles | ) |

Sets the quaternion from euler angles.

Parameters

  angles | The euler angles to translate, considering rotation in ZYX (Yaw-Pitch-Roll) order.

Returns
  Reference over caller.

## ◆ setFromRotationBetween()

Quaternion& nkMaths::Quaternion::setFromRotationBetween | ( | const Vector & | a,
|  | const Vector & | b
| ) |  |

Sets the quaternion from the rotation needed to rotate from one direction to another.

Parameters

  a | The vector to rotate from.
  b | The vector to rotate to.

Returns
  Reference over caller.

## ◆ setFromOrientationMatrix()

Quaternion& nkMaths::Quaternion::setFromOrientationMatrix | ( | const Matrix & | mat | ) |

Sets the quaternion from a rotation matrix.

Parameters

  mat | The matrix to extract the rotation from.

Returns
  Reference over caller.

## ◆ setFromTransformationMatrix()

Quaternion& nkMaths::Quaternion::setFromTransformationMatrix | ( | const Matrix & | mat | ) |

Sets the quaternion from a full transformation matrix.

Parameters

  mat | The matrix to extract the rotation from.

Returns
  Reference over caller.

## ◆ transform()

Vector nkMaths::Quaternion::transform | ( | const Vector & | vector | ) | const

Rotates a vector, by copying it and returning it. Another way to express q * v.

Parameters

  vector | The vector to rotate.

Returns
  The vector once rotated.

## ◆ apply()

Vector& nkMaths::Quaternion::apply | ( | Vector & | vector | ) | const

Rotates a vector, by altering the vector parameter. Another way to express q *= v.

Parameters

  vector | The vector to rotate.

Returns
  The vector given, once rotated.

## ◆ toString()

nkMemory::String nkMaths::Quaternion::toString | ( |  | ) | const

Returns
  The quaternion expressed as a string, formatted as "x, y, z, w".

## ◆ fromString()

Quaternion& nkMaths::Quaternion::fromString | ( | nkMemory::StringView | str | ) |

Parse components from a string. Format is "x,y,z,w".

Parameters

  str | The string to parse.

Returns
  The updated quaternion instance.

## ◆ operator=()

Quaternion& nkMaths::Quaternion::operator= | ( | const Quaternion & | other | ) |
| noexcept

Assignment operator.

Parameters

  other | The quaternion to assign.

## ◆ operator*() [1/2]

Vector nkMaths::Quaternion::operator* | ( | const Vector & | other | ) | const

Multiplication operator.

Parameters

  other | The vector to apply the quaternion to.

Returns
  The vector, rotated by the quaternion.

## ◆ operator*() [2/2]

Quaternion nkMaths::Quaternion::operator* | ( | const Quaternion & | other | ) | const

Multiplication operator.

Parameters

  other | The quaternion to multiply with.

Returns
  A quaternion being the result of the multiplication of both quaternions.

## ◆ operator*=()

void nkMaths::Quaternion::operator*= | ( | const Quaternion & | other | ) |

Multiplication and assignment operator.

Parameters

  other | The quaternion to multiply with.

## ◆ operator==()

bool nkMaths::Quaternion::operator== | ( | const Quaternion & | other | ) | const

Comparison operator.

Parameters

  other | The quaternion to compare with.

Returns
  Whether the quaternions have the same component values (true) or not (false).

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsMaths/Algebra/Quaternion.h